package com.youku.core.view
{
   import com.youku.core.view.components.CoreBase;
   import flash.display.MovieClip;
   import com.youku.interfaces.IRootData;
   import com.youku.core.model.vo.PlayListData;
   import com.youku.interfaces.IPlayerProxy;
   import flash.utils.Timer;
   import com.youku.events.PlayerControlEvent;
   import com.youku.events.ConductorEvent;
   import com.youku.events.CoreFacadeEvent;
   import com.youku.PlayerConfig;
   import com.youku.error.ErrorLevel;
   import com.youku.error.ErrorCode;
   import com.youku.error.ErrorType;
   import com.youku.error.ErrorConstant;
   import com.youku.events.PluginEvent;
   import flash.utils.getTimer;
   import com.youku.data.LoadTimeData;
   import com.youku.events.ReportEvent;
   import com.youku.conductor.ConductorState;
   import com.youku.data.PlayerConstant;
   import com.youku.utils.Tweener;
   import com.youku.events.CoreEvent;
   import com.youku.P2PConfig;
   import com.youku.core.model.PlayPolicyProxy;
   import com.youku.core.view.events.PlayPolicyEvent;
   import com.youku.P2PLoader;
   import flash.events.Event;
   import com.youku.utils.FlashVersionCheck;
   import com.youku.GlobalService;
   import com.youku.GlobalServiceKeys;
   import flash.system.SystemUpdater;
   import flash.events.ProgressEvent;
   import flash.events.StatusEvent;
   import flash.events.IOErrorEvent;
   import flash.events.SecurityErrorEvent;
   import flash.events.TimerEvent;
   import flash.system.SystemUpdaterType;
   import flash.external.ExternalInterface;
   import com.youku.core.CoreContext;
   
   public class CoreMediator extends Object
   {
      
      public function CoreMediator(param1:MovieClip, param2:IPlayerProxy) {
         this._p2plibDep = new Object();
         super();
         this._mainMc = param1;
         this._playerProxy = param2;
         CoreContext.playerProxy = param2;
         this._width = PlayerConfig.normalVideoWidth;
         this._height = PlayerConfig.normalVideoHeight;
         this._volume = 0.5;
         this._screenMode = param2.fsoProxy.getScreenMode();
         this._firstGetPlaylist = true;
      }
      
      private var _core:CoreBase;
      
      private var _mainMc:MovieClip;
      
      private var _rootData:IRootData;
      
      private var _playListData:PlayListData;
      
      private var _playListDataCache:PlayListData;
      
      private var _playerProxy:IPlayerProxy;
      
      private var _isIkuReportSend:Boolean;
      
      private var _width:Number;
      
      private var _height:Number;
      
      private var _volume:Number;
      
      private var _screenMode:String;
      
      private var _isBufferInfoShowed:Boolean = false;
      
      private var _firstGetPlaylist:Boolean = true;
      
      private var _p2plibDep:Object;
      
      private var _ltgetplaylist:Number = 0;
      
      private var _stgetplaylist:Number = 0;
      
      private var _isDRMUpdated:Boolean = false;
      
      private var _DRMUpdateTimer:Timer;
      
      private const DRM_UPDATE_TIMEOUT:int = 10000;
      
      private var _showTimeoutCount:int = 0;
      
      public function init() : void {
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_PLAY,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_PLAY_WAIT_LOAD,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_SEEK,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_MOCKSEEK,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_PAUSE,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_RESUME,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_TOGGLE_PAUSEPLAY,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_DRAGGING,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_CHANGE_SCREEN_MODE,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_CHANGE_QUALITY,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_CHANGE_ADJUST_PARAMETERS,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_PLAY_NEW_VIDEO,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_TWEEN_HIDE_AND_PAUSE,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_TWEEN_SHOW_AND_PLAY,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_JUMP_TAIL,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_RECORD_POSITION,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_OTHER_RENDER,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.COMMON_RESET,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.COMMON_ERROR,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.COMMON_CHANGE_VOLUME,this.onPlayerConfigChanged);
         this._playerProxy.addEventListener(PlayerControlEvent.FULLSCREEN_CHANGED,this.onPlayerConfigChanged);
         this._playerProxy.addEventListener(PlayerControlEvent.PLAYER_SIZE_CHANGED,this.onPlayerConfigChanged);
         this._playerProxy.addEventListener(PlayerControlEvent.PLAYER_ROTATION_CHANGED,this.onPlayerConfigChanged);
         this._playerProxy.addEventListener(PlayerControlEvent.HIDE_ALERT_BOX,this.onAlertBoxHide);
         this._playerProxy.addEventListener(ConductorEvent.STATE_CHANGED,this.onConductorEvent);
         this._playerProxy.addEventListener(CoreFacadeEvent.ROOT_DATA_LOADED,this.onCoreFacadeEvent);
         this._playerProxy.addEventListener(CoreFacadeEvent.PLAY_LIST_DATA_LOADED,this.onCoreFacadeEvent);
         this._playerProxy.addEventListener(CoreFacadeEvent.PLAY_LIST_DATA_LOAD_FATAL_ERROR,this.onCoreFacadeEvent);
         this._playerProxy.addEventListener(CoreFacadeEvent.PLAY_LIST_DATA_LOAD_ERROR,this.onCoreFacadeEvent);
         this._playerProxy.addEventListener(CoreFacadeEvent.PLAY_LIST_DATA_LOAD_NO_DATA,this.onCoreFacadeEvent);
         this._rootData = PlayerConfig.rootData;
         this.playVideoByID(this._rootData.videoId);
      }
      
      private function onCoreFacadeEvent(param1:CoreFacadeEvent) : void {
         var _loc2_:String = null;
         var _loc3_:String = null;
         var _loc4_:String = null;
         var _loc5_:String = null;
         var _loc6_:Object = null;
         switch(param1.type)
         {
            case CoreFacadeEvent.PLAY_LIST_DATA_LOADED:
               this.playListDataDone(param1.data as PlayListData);
               break;
            case CoreFacadeEvent.PLAY_LIST_DATA_LOAD_FATAL_ERROR:
               _loc2_ = ErrorLevel.FATAL_ERROR;
               _loc3_ = ErrorCode.PLAY_LIST_DEFAULT_ERROR;
               _loc4_ = ErrorType.NORMAL_ERROR;
               _loc5_ = "";
               if(param1.data.type == "noData")
               {
                  _loc5_ = ErrorConstant.PLAY_LIST_DATA_ERROR;
                  _loc3_ = ErrorCode.PLAY_LIST_DATA_ERROR;
               }
               else if(param1.data.type == "noConnect")
               {
                  _loc5_ = ErrorConstant.PLAY_LIST_DATA_LOAD_FAIL;
                  _loc3_ = ErrorCode.PLAY_LIST_DATA_LOAD_FAIL;
               }
               else if(param1.data.type == "nosid")
               {
                  _loc5_ = ErrorConstant.PLAY_LIST_NO_SID;
                  _loc3_ = ErrorCode.PLAY_LIST_NO_SID;
               }
               
               
               this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.PLUGIN_ERROR,
                  {
                     "level":_loc2_,
                     "message":_loc5_,
                     "type":_loc4_,
                     "code":_loc3_
                  }));
               this._ltgetplaylist = getTimer() - this._stgetplaylist;
               _loc6_ = {};
               _loc6_.type = "error";
               _loc6_.stage = LoadTimeData.LOAD_STAGE_GETPLAYLIST;
               _loc6_.info = _loc3_;
               this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.PLAYER_LOAD_TIME_EVENT,_loc6_));
               this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.LOAD_TIME_REPORT,
                  {
                     "isError":true,
                     "type":LoadTimeData.TYPE_GETPLAYLIST,
                     "errorCode":LoadTimeData.ERROR_CODE_DATA
                  }));
               break;
            case CoreFacadeEvent.PLAY_LIST_DATA_LOAD_ERROR:
               this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.DYNAMIC_REPORT,
                  {
                     "code":"1002",
                     "number":0
                  }));
               break;
            case CoreFacadeEvent.PLAY_LIST_DATA_LOAD_NO_DATA:
               this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.DYNAMIC_REPORT,
                  {
                     "code":"1003",
                     "number":0
                  }));
               break;
         }
      }
      
      private function onConductorEvent(param1:ConductorEvent) : void {
         var _loc2_:String = null;
         if(this._core == null)
         {
            return;
         }
         switch(param1.type)
         {
            case ConductorEvent.STATE_CHANGED:
               _loc2_ = param1.data as String;
               if(_loc2_ == ConductorState.ERROR)
               {
                  this._core.close();
               }
               else if(_loc2_ == ConductorState.READY_TO_PLAY)
               {
                  if(this._playerProxy.playerData.isInFullScreen)
                  {
                     this._core.setScreenMode(this._screenMode,false,true);
                  }
                  else
                  {
                     this._core.setScreenMode(PlayerConstant.SCREEN_MODE_100,false,false);
                  }
               }
               else if(_loc2_ == ConductorState.PRE_VIDEO)
               {
                  this._core.startToPlay();
               }
               
               
               break;
         }
      }
      
      private function onPlayerControlEvent(param1:PlayerControlEvent) : void {
         var contrast:Number = NaN;
         var bright:Number = NaN;
         var saturation:Number = NaN;
         var adtype:String = null;
         var stopSize:Boolean = false;
         var e:PlayerControlEvent = param1;
         var time:Number = 0;
         var jump:Boolean = false;
         var change:Boolean = false;
         var mode:String = "100";
         var tween:Boolean = false;
         var dragging:Boolean = false;
         var volume:Number = 0;
         var quality:String = "";
         var useraction:Boolean = false;
         var starttime:Number = 0;
         if(e.type == PlayerControlEvent.CORE_PLAY_NEW_VIDEO)
         {
            if(PlayerConfig.dvdPlay)
            {
               this.playVideoByID(e.data as String,PlayerConfig.dvdVoiceVid);
            }
            else
            {
               this.playVideoByID(e.data as String);
            }
            return;
         }
         if(this._core == null)
         {
            return;
         }
         if(this._core.closed)
         {
            return;
         }
         switch(e.type)
         {
            case PlayerControlEvent.CORE_PLAY:
               starttime = 0;
               if(e.data.starttime != null)
               {
                  starttime = e.data.starttime;
               }
               this._core.play(starttime);
               break;
            case PlayerControlEvent.CORE_PLAY_WAIT_LOAD:
               starttime = 0;
               if(e.data.starttime != null)
               {
                  starttime = e.data.starttime;
               }
               this._core.playWaitLoad(starttime);
               break;
            case PlayerControlEvent.CORE_SEEK:
               time = e.data.time;
               this._core.seek(time);
               break;
            case PlayerControlEvent.CORE_MOCKSEEK:
               time = e.data.time;
               this._core.mockSeek(time);
               break;
            case PlayerControlEvent.CORE_PAUSE:
               useraction = e.data.useraction;
               this._core.pause(useraction);
               break;
            case PlayerControlEvent.CORE_RESUME:
               this._core.resume();
               break;
            case PlayerControlEvent.CORE_TOGGLE_PAUSEPLAY:
               useraction = e.data.useraction;
               this._core.togglePausePlay(useraction);
               break;
            case PlayerControlEvent.CORE_DRAGGING:
               dragging = e.data.dragging;
               this._core.setDragging(dragging);
               break;
            case PlayerControlEvent.CORE_CHANGE_SCREEN_MODE:
               mode = e.data.mode;
               tween = e.data.tween;
               this._screenMode = mode;
               this._core.setScreenMode(mode,tween,true);
               break;
            case PlayerControlEvent.CORE_CHANGE_QUALITY:
               quality = e.data.quality;
               this._core.setQuality(quality);
               break;
            case PlayerControlEvent.CORE_CHANGE_ADJUST_PARAMETERS:
               contrast = e.data.contrast;
               bright = e.data.bright;
               saturation = e.data.saturation;
               this._core.setAdjustParameter(contrast,bright,saturation);
               break;
            case PlayerControlEvent.CORE_TWEEN_HIDE_AND_PAUSE:
               this._core.alpha = 1;
               this._core.visible = true;
               Tweener.to(this._core,0.5,
                  {
                     "alpha":0,
                     "onComplete":function():void
                     {
                        _core.visible = false;
                        _core.pause();
                        _playerProxy.dispatchEvent(new CoreEvent(CoreEvent.TWEEN_HIDE_COMPLETE));
                     }
                  });
               break;
            case PlayerControlEvent.CORE_TWEEN_SHOW_AND_PLAY:
               adtype = "";
               if((e.data) && (e.data.hasOwnProperty("adtype")))
               {
                  adtype = e.data.adtype;
               }
               if(adtype != "middle")
               {
                  this._core.alpha = 1;
                  this._core.visible = true;
                  this._core.resume();
               }
               else
               {
                  this._core.visible = true;
                  this._core.alpha = 0;
                  Tweener.to(this._core,0.5,
                     {
                        "alpha":1,
                        "onComplete":function():void
                        {
                           _core.resume();
                        }
                     });
               }
               break;
            case PlayerControlEvent.COMMON_RESET:
            case PlayerControlEvent.COMMON_ERROR:
               this.reset();
               this._core.close();
               break;
            case PlayerControlEvent.CORE_JUMP_TAIL:
               this._core.jumpTail();
               break;
            case PlayerControlEvent.CORE_RECORD_POSITION:
               this._core.saveWatchingRecord();
               break;
            case PlayerControlEvent.CORE_OTHER_RENDER:
               stopSize = true;
               if((e.data) && e.data.stop == false)
               {
                  stopSize = false;
               }
               this._core.stopSizeRender(stopSize);
               break;
         }
      }
      
      private function reset() : void {
         this._isBufferInfoShowed = false;
         this._firstGetPlaylist = true;
      }
      
      private function onPlayerConfigChanged(param1:PlayerControlEvent) : void {
         var _loc2_:* = NaN;
         var _loc3_:* = false;
         var _loc4_:* = NaN;
         var _loc5_:* = NaN;
         var _loc6_:* = NaN;
         switch(param1.type)
         {
            case PlayerControlEvent.COMMON_CHANGE_VOLUME:
               this._volume = param1.data.volume;
               if(this._core)
               {
                  this._core.volume = this._volume;
               }
               break;
            case PlayerControlEvent.PLAYER_ROTATION_CHANGED:
               _loc2_ = Number(param1.data.angle);
               if(!isNaN(_loc2_))
               {
                  this._core.setAngle(_loc2_);
               }
               break;
            case PlayerControlEvent.PLAYER_SIZE_CHANGED:
            case PlayerControlEvent.FULLSCREEN_CHANGED:
               _loc3_ = param1.data.fullscreen;
               _loc4_ = param1.data.width;
               _loc5_ = param1.data.height;
               _loc6_ = param1.data.cheight;
               if(_loc3_)
               {
                  this._width = _loc4_;
                  this._height = _loc5_;
               }
               else
               {
                  this._width = _loc4_;
                  this._height = _loc5_ - _loc6_;
               }
               if(this._core)
               {
                  this._core.setWH(this._width,this._height);
                  if(_loc3_)
                  {
                     this._core.setScreenMode(this._screenMode,false,true);
                  }
                  else
                  {
                     this._core.setScreenMode(PlayerConstant.SCREEN_MODE_100,false,false);
                  }
               }
               break;
         }
      }
      
      private function playListDataDone(param1:PlayListData) : void {
         var _loc2_:String = this.checkLoadDVDVideo(param1);
         if(_loc2_ != "")
         {
            PlayerConfig.dvdSID = param1.sid;
            PlayerConfig.dvdoip = param1.oip;
            PlayerConfig.dvdtoken = param1.tk;
            this.playVideoByID(param1.vidEncoded,_loc2_);
            return;
         }
         this._playListDataCache = param1;
         var _loc3_:Boolean = this.checkVIP1080P(this._playListDataCache);
         if(!_loc3_)
         {
            this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.ALERT_BOX_SHOW,
               {
                  "type":"1080P",
                  "from":"core"
               }));
            return;
         }
         this.playListDataHandle();
      }
      
      private function playListDataHandle() : void {
         this._rootData.firstQuality = "";
         this._playListData = this._playListDataCache;
         var _loc1_:Object = {};
         _loc1_.playListData = this._playListDataCache;
         var _loc2_:CoreEvent = new CoreEvent(CoreEvent.PLAYLIST_DADA_LOADED,_loc1_);
         this._playerProxy.dispatchEvent(_loc2_);
         var _loc3_:Boolean = this.checkError();
         if(_loc3_)
         {
            return;
         }
         var _loc4_:Number = getTimer();
         this._ltgetplaylist = _loc4_ - this._stgetplaylist;
         PlayerConfig.loadtimeData.ltgetplaylist_end = new Date().getTime();
         PlayerConfig.loadtimeData.ltgetplaylist = this._ltgetplaylist;
         this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.LOAD_TIME_REPORT,
            {
               "isError":false,
               "type":LoadTimeData.TYPE_GETPLAYLIST,
               "errorCode":null
            }));
         this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.EX_ADD_DEPENDECE,this._p2plibDep));
         var _loc5_:* = true;
         if(P2PConfig.InitP2PType == "ss" || (P2PConfig.isYoukuP2PPlayer) || P2PConfig.InitP2PType == "ppweb" && (_loc5_))
         {
            this.loadPlayPolicy();
         }
         else
         {
            this.createCore();
         }
      }
      
      private function onAlertBoxHide(param1:PlayerControlEvent) : void {
         if(param1.data.from == "core")
         {
            this.playListDataHandle();
         }
      }
      
      private function checkVIP1080P(param1:PlayListData) : Boolean {
         if((param1.has1080P) && this._rootData.firstQuality == PlayerConstant.QUALITY_1080P)
         {
            if(param1.controller.hd3_enabled == true)
            {
               return true;
            }
            return false;
         }
         return true;
      }
      
      private function loadPlayPolicy() : void {
         var _loc1_:PlayPolicyProxy = null;
         if(!PlayerConfig.rootData.policy)
         {
            _loc1_ = new PlayPolicyProxy();
            _loc1_.addEventListener(PlayPolicyEvent.PLAY_POLICY_READY,this.onPlayPolicyReady);
            _loc1_.loadPolicy();
         }
         else
         {
            if(P2PConfig.isYoukuP2PPlayer)
            {
               P2PConfig.isYKUseP2P = PlayerConfig.rootData.allowP2P;
            }
            this.onPlayPolicyReady(new PlayPolicyEvent(PlayPolicyEvent.PLAY_POLICY_READY,{"allow":true}));
         }
      }
      
      private function onPlayPolicyReady(param1:PlayPolicyEvent) : void {
         var _loc2_:Boolean = param1.data.allow;
         if((_loc2_) || (P2PConfig.isYoukuP2PPlayer))
         {
            if(PlayerConfig.specialType == PlayerConstant.SPECIAL_TYPE_SHENHE)
            {
               P2PConfig.isYKUseP2P = false;
            }
            this.loadP2PLib();
         }
         else
         {
            this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.PLAY_POLICY_ALLOW,{"allow":0}));
            P2PConfig.P2PStatus = P2PConfig.DONT_LOAD_ERROR;
            this.createCore();
         }
      }
      
      private function loadP2PLib() : void {
         var _loc1_:Boolean = this._playerProxy.playerData.isIKuInstall;
         if(_loc1_)
         {
            this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.PLAYVV_IKU,{}));
            P2PConfig.P2PStatus = P2PConfig.DONT_LOAD_ERROR;
            this.createCore();
            return;
         }
         this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.LOAD_P2P_SWC,{}));
         var _loc2_:String = this._playerProxy.rootGetData.rootBaseURL;
         var _loc3_:P2PLoader = new P2PLoader();
         _loc3_.addEventListener(P2PLoader.COMPLETE,this.onP2PLoadComplete);
         _loc3_.load(_loc2_);
      }
      
      private function onP2PLoadComplete(param1:Event) : void {
         this.createCore();
      }
      
      private function checkLoadDVDVideo(param1:PlayListData) : String {
         var _loc4_:String = null;
         var _loc2_:String = param1.currentLang;
         if(_loc2_ == "")
         {
            return _loc2_;
         }
         var _loc3_:* = "";
         if(this._firstGetPlaylist)
         {
            _loc4_ = this._playerProxy.fsoProxy.getDefaultVoice();
            if(_loc4_ == "default")
            {
               _loc4_ = _loc2_;
            }
            if(_loc2_ != _loc4_)
            {
               _loc3_ = this.getVidByLang(_loc4_,param1);
            }
            this._firstGetPlaylist = false;
         }
         if(this._rootData.lang != "")
         {
            if(_loc2_ != this._rootData.lang)
            {
               _loc3_ = this.getVidByLang(this._rootData.lang,param1);
            }
            this._rootData.lang = "";
         }
         return _loc3_;
      }
      
      private function getVidByLang(param1:String, param2:PlayListData) : String {
         var _loc3_:* = "";
         var _loc4_:* = 0;
         while(_loc4_ < param2.dvdinfo.audioLangs.length)
         {
            if(param2.dvdinfo.audioLangs[_loc4_].lang == param1)
            {
               _loc3_ = param2.dvdinfo.audioLangs[_loc4_].vid;
            }
            _loc4_++;
         }
         return _loc3_;
      }
      
      private function getLangByVid(param1:String, param2:PlayListData) : String {
         var _loc3_:* = "";
         var _loc4_:* = 0;
         while(_loc4_ < param2.dvdinfo.audioLangs.length)
         {
            if(param2.dvdinfo.audioLangs[_loc4_].vid == param1)
            {
               _loc3_ = param2.dvdinfo.audioLangs[_loc4_].lang;
            }
            _loc4_++;
         }
         return _loc3_;
      }
      
      private function checkError() : Boolean {
         var _loc1_:* = false;
         var _loc2_:* = 0;
         var _loc3_:String = null;
         var _loc4_:String = null;
         var _loc5_:String = null;
         var _loc6_:String = null;
         var _loc7_:String = null;
         if(!(this._rootData.playURL == null) && !(this._rootData.playURL == ""))
         {
            return false;
         }
         if(this._playListData.sid == null || this._playListData.sid == "")
         {
            this._playerProxy.dispatchEvent(new CoreFacadeEvent(CoreFacadeEvent.PLAY_LIST_DATA_LOAD_FATAL_ERROR,{"type":"nosid"}));
            return true;
         }
         if((this._playListData.rtmp) || (this._playListData.drm))
         {
            _loc1_ = this.checkFlashVersion();
            if(!_loc1_)
            {
               this.flashVersionCheckError();
               return true;
            }
         }
         if(this._playListData.currentFileId.length <= 3)
         {
            if(this._playListData.currentFileId == "")
            {
               this._playerProxy.dispatchEvent(new CoreFacadeEvent(CoreFacadeEvent.PLAY_LIST_DATA_LOAD_FATAL_ERROR,{"type":"noData"}));
               return true;
            }
            _loc2_ = int(this._playListData.currentFileId);
            if(_loc2_ > 0)
            {
               return false;
            }
            _loc3_ = ErrorCode.NORMAL_ERROR;
            _loc4_ = String(_loc2_);
            _loc5_ = ErrorType.NORMAL_ERROR;
            _loc6_ = ErrorLevel.FATAL_ERROR;
            _loc7_ = this._playListData.error == null?"":this._playListData.error;
            if(!(_loc2_ == -10 || _loc2_ == -11))
            {
               if(_loc2_ == -6 || _loc2_ == -7)
               {
                  _loc5_ = ErrorType.NEED_PASSWORD;
                  _loc3_ = ErrorCode.NEED_PASSWORD;
               }
               else if(_loc2_ == -12)
               {
                  _loc5_ = ErrorType.PAY_LOGINED_BUY;
                  _loc3_ = ErrorCode.PAY_LOGINED_BUY;
               }
               else if(_loc2_ == -13)
               {
                  _loc5_ = ErrorType.PAY_NOT_LOGIN;
                  _loc3_ = ErrorCode.PAY_NOT_LOGIN;
               }
               else if(_loc2_ == -14)
               {
                  _loc5_ = ErrorType.PAY_LIMIT_COUNT;
                  _loc3_ = ErrorCode.PAY_LIMIT_COUNT;
               }
               else if(_loc2_ != -8)
               {
                  if(_loc2_ == -5)
                  {
                     _loc5_ = ErrorType.NORMAL_ERROR;
                     _loc3_ = ErrorCode.NORMAL_ERROR;
                  }
                  else if(_loc2_ == -16)
                  {
                     _loc5_ = ErrorType.PAY_OUT_OF_DATE;
                     _loc3_ = ErrorCode.PAY_OUT_OF_DATE;
                  }
                  else
                  {
                     _loc5_ = ErrorType.NORMAL_ERROR;
                     _loc3_ = ErrorCode.NORMAL_ERROR;
                  }
                  
               }
               
               
               
               
            }
            this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.LOAD_TIME_REPORT,
               {
                  "isError":true,
                  "type":LoadTimeData.TYPE_GETPLAYLIST,
                  "errorCode":LoadTimeData.ERROR_CODE_GETPLAYLIST + String(_loc2_)
               }));
            this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.PLUGIN_ERROR,
               {
                  "level":_loc6_,
                  "message":_loc7_,
                  "type":_loc5_,
                  "code":_loc3_,
                  "oricode":_loc4_
               }));
            return true;
         }
         if(this._playListData.segArr == null || this._playListData.segArr.length == 0)
         {
            this._playerProxy.dispatchEvent(new CoreFacadeEvent(CoreFacadeEvent.PLAY_LIST_DATA_LOAD_FATAL_ERROR,{"type":"noData"}));
            return true;
         }
         return false;
      }
      
      private function checkFlashVersion() : Boolean {
         var _loc1_:Boolean = FlashVersionCheck.checkVersionForNewVersion();
         if(_loc1_)
         {
            return true;
         }
         return false;
      }
      
      private function flashVersionCheckError() : void {
         var _loc1_:Object = {};
         _loc1_.level = ErrorLevel.FATAL_ERROR;
         _loc1_.code = ErrorCode.FLASH_VERSION_LOW;
         _loc1_.type = ErrorType.NORMAL_ERROR;
         _loc1_.message = ErrorConstant.FLASH_VERSION_LOW;
         var _loc2_:PluginEvent = new PluginEvent(PluginEvent.PLUGIN_ERROR,_loc1_);
         this._playerProxy.dispatchEvent(_loc2_);
      }
      
      private function createCore() : void {
         var _loc2_:CoreEvent = null;
         if((this._playListData.drm) && !this._isDRMUpdated)
         {
            this.updateDRMModule();
            return;
         }
         this._isIkuReportSend = false;
         var _loc1_:Object = {};
         if(this._core)
         {
            this._core.reInit();
            _loc1_ = {};
            _loc1_.core = this._core;
            _loc2_ = new CoreEvent(CoreEvent.CORE_INITED,_loc1_);
            this._playerProxy.dispatchEvent(_loc2_);
         }
         else
         {
            this._core = new CoreBase(this._playerProxy);
            this._mainMc.addChild(this._core);
            this.attchCoreEvents();
            this._core.init(this._width,this._height);
            this._core.volume = this._volume;
            this._core.x = this._core.y = 0;
            GlobalService.addService(GlobalServiceKeys.CORE,this._core);
            _loc1_ = {};
            _loc1_.core = this._core;
            _loc2_ = new CoreEvent(CoreEvent.CORE_INITED,_loc1_);
            this._playerProxy.dispatchEvent(_loc2_);
         }
         this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.EX_REMOVE_DEPENDECE,this._p2plibDep));
      }
      
      private function updateDRMModule() : void {
         var _loc1_:SystemUpdater = new SystemUpdater();
         _loc1_.addEventListener(Event.COMPLETE,this.onDRMModuleUpdated);
         _loc1_.addEventListener(ProgressEvent.PROGRESS,this.onDRMModuleEvent);
         _loc1_.addEventListener(Event.OPEN,this.onDRMModuleEvent);
         _loc1_.addEventListener(StatusEvent.STATUS,this.onDRMModuleStatus);
         _loc1_.addEventListener(IOErrorEvent.IO_ERROR,this.onDRMModuleError);
         _loc1_.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onDRMModuleError);
         this._DRMUpdateTimer = new Timer(this.DRM_UPDATE_TIMEOUT);
         this._DRMUpdateTimer.addEventListener(TimerEvent.TIMER,this.onDRMUpdateTimeout);
         this._DRMUpdateTimer.start();
         _loc1_.update(SystemUpdaterType.DRM);
      }
      
      private function onDRMUpdateTimeout(param1:TimerEvent) : void {
         this._DRMUpdateTimer.stop();
         var _loc2_:String = ErrorLevel.FATAL_ERROR;
         var _loc3_:String = ErrorType.NORMAL_ERROR;
         var _loc4_:String = ErrorConstant.DRM_CHANGE_BROWSER;
         var _loc5_:String = ErrorCode.DRM_CHANGE_BROWSER;
         this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.PLUGIN_ERROR,
            {
               "level":_loc2_,
               "message":_loc4_,
               "type":_loc3_,
               "code":_loc5_
            }));
      }
      
      private function onDRMModuleError(param1:Event) : void {
         this._DRMUpdateTimer.stop();
      }
      
      private function onDRMModuleStatus(param1:StatusEvent) : void {
         this._DRMUpdateTimer.stop();
         this._isDRMUpdated = false;
         var _loc2_:String = ErrorLevel.FATAL_ERROR;
         var _loc3_:String = ErrorType.NORMAL_ERROR;
         var _loc4_:String = ErrorConstant.DRM_FLASH_VERSION_LOW;
         var _loc5_:String = ErrorCode.DRM_FLASH_VERSION_LOW;
         this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.PLUGIN_ERROR,
            {
               "level":_loc2_,
               "message":_loc4_,
               "type":_loc3_,
               "code":_loc5_
            }));
      }
      
      private function onDRMModuleEvent(param1:Event) : void {
         this._DRMUpdateTimer.stop();
      }
      
      private function onDRMModuleUpdated(param1:Event) : void {
         this._DRMUpdateTimer.stop();
         this._isDRMUpdated = true;
         this.createCore();
      }
      
      private function attchCoreEvents() : void {
         if(this._core == null)
         {
            return;
         }
         this._core.addEventListener(CoreEvent.PLAY_VIDEO_BY_ID,this.onCoreEvent);
         this._core.addEventListener(CoreEvent.SEND_STATIC_REPORT,this.onCoreEvent);
         this._core.addEventListener(CoreEvent.SEND_DYNAMIC_REPORT,this.onCoreEvent);
         this._core.addEventListener(CoreEvent.SEND_WASTE_REPORT,this.onCoreEvent);
         this._core.addEventListener(CoreEvent.BUFFER_APPEARED,this.onCoreEvent);
         this._core.addEventListener(CoreEvent.BUFFER_COUNT_LIMITED,this.onCoreEvent);
         this._core.addEventListener(CoreEvent.BUFFER_TIMEOUT,this.onCoreEvent);
         this._core.addEventListener(CoreEvent.SEND_VIDEO_TIME_REPORT,this.onCoreEvent);
         this._core.addEventListener(CoreEvent.SEND_WPLAY_LOG_REPORT,this.onCoreEvent);
         this._core.addEventListener(CoreEvent.VIDEO_NOT_FOUND,this.onCoreEvent);
         this._core.addEventListener(CoreEvent.VIDEO_NOT_CONNECTED,this.onCoreEvent);
         this._core.addEventListener(CoreEvent.VIDEO_RTMP_FAIL,this.onCoreEvent);
         this._core.addEventListener(CoreEvent.VIDEO_DRM_NOT_SUPPORT,this.onCoreEvent);
         this._core.addEventListener(CoreEvent.VIDEO_EARLY_REQUEST,this.onCoreEvent);
      }
      
      private function onCoreEvent(param1:CoreEvent) : void {
         var _loc2_:String = null;
         var _loc3_:String = null;
         var _loc4_:* = NaN;
         var _loc5_:String = null;
         var _loc6_:String = null;
         var _loc7_:String = null;
         switch(param1.type)
         {
            case CoreEvent.PLAY_VIDEO_BY_ID:
               this.playVideoByID(param1.data.videoId);
               break;
            case CoreEvent.SEND_STATIC_REPORT:
               this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.STATIC_REPORT));
               break;
            case CoreEvent.SEND_DYNAMIC_REPORT:
               _loc2_ = param1.data.code;
               _loc3_ = param1.data.number;
               this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.DYNAMIC_REPORT,
                  {
                     "code":_loc2_,
                     "number":_loc3_
                  }));
               break;
            case CoreEvent.SEND_WASTE_REPORT:
               _loc3_ = param1.data.number;
               this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.WASTE_REPORT,{"number":_loc3_}));
               break;
            case CoreEvent.BUFFER_APPEARED:
               this.onCoreBuffer(param1);
               break;
            case CoreEvent.BUFFER_COUNT_LIMITED:
               this.tryToShowInformation();
               break;
            case CoreEvent.BUFFER_TIMEOUT:
               this.showInformationTimeout();
               break;
            case CoreEvent.SEND_VIDEO_TIME_REPORT:
               _loc4_ = param1.data.times;
               this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.VIDEO_TIME_REPORT,param1.data));
               break;
            case CoreEvent.SEND_WPLAY_LOG_REPORT:
               this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.WPLAY_LOG_REPORT));
               break;
            case CoreEvent.VIDEO_NOT_CONNECTED:
               _loc5_ = ErrorLevel.FATAL_ERROR;
               _loc6_ = ErrorType.NORMAL_ERROR;
               _loc7_ = ErrorConstant.VIDEO_CONNECT_FAIL;
               _loc2_ = ErrorCode.VIDEO_CONNECT_FAIL;
               this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.PLUGIN_ERROR,
                  {
                     "level":_loc5_,
                     "message":_loc7_,
                     "type":_loc6_,
                     "code":_loc2_
                  }));
               break;
            case CoreEvent.VIDEO_NOT_FOUND:
               _loc5_ = ErrorLevel.FATAL_ERROR;
               _loc6_ = ErrorType.NORMAL_ERROR;
               _loc7_ = ErrorConstant.VIDEO_NOT_FOUND;
               _loc2_ = ErrorCode.VIDEO_NOT_FOUND;
               this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.PLUGIN_ERROR,
                  {
                     "level":_loc5_,
                     "message":_loc7_,
                     "type":_loc6_,
                     "code":_loc2_
                  }));
               break;
            case CoreEvent.VIDEO_RTMP_FAIL:
               _loc5_ = ErrorLevel.FATAL_ERROR;
               _loc6_ = ErrorType.NORMAL_ERROR;
               _loc7_ = ErrorConstant.VIDEO_RTMP_FAIL;
               _loc2_ = ErrorCode.VIDEO_RTMP_FAIL;
               this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.PLUGIN_ERROR,
                  {
                     "level":_loc5_,
                     "message":_loc7_,
                     "type":_loc6_,
                     "code":_loc2_
                  }));
               break;
            case CoreEvent.VIDEO_DRM_NOT_SUPPORT:
               _loc5_ = ErrorLevel.FATAL_ERROR;
               _loc6_ = ErrorType.NORMAL_ERROR;
               _loc7_ = ErrorConstant.DRM_CHANGE_BROWSER;
               _loc2_ = ErrorCode.DRM_CHANGE_BROWSER;
               this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.PLUGIN_ERROR,
                  {
                     "level":_loc5_,
                     "message":_loc7_,
                     "type":_loc6_,
                     "code":_loc2_
                  }));
               break;
            case CoreEvent.VIDEO_EARLY_REQUEST:
               ExternalInterface.call("ljllq");
               _loc5_ = ErrorLevel.FATAL_ERROR;
               _loc6_ = ErrorType.CHANGE_BROWSER_ERROR;
               _loc7_ = "ad_blocked";
               _loc2_ = ErrorCode.AD_BLOCKED;
               this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.PLUGIN_ERROR,
                  {
                     "level":_loc5_,
                     "message":_loc7_,
                     "type":_loc6_,
                     "code":_loc2_
                  }));
               this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.AD_BLOCK_REPORT,
                  {
                     "st":1,
                     "bt":1
                  }));
               break;
         }
      }
      
      private function onCoreBuffer(param1:CoreEvent) : void {
         var _loc2_:Number = param1.data.number;
         if((this._playerProxy.playerData.isIKuCanSendLog) && this._isIkuReportSend == false)
         {
            this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.IKU_REPORT));
            this._isIkuReportSend = true;
         }
         this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.DYNAMIC_REPORT,
            {
               "code":"3003",
               "number":_loc2_
            }));
         this._playerProxy.dispatchEvent(new CoreEvent(CoreEvent.BUFFER_APPEARED));
      }
      
      private function showInformationTimeout() : void {
         var _loc1_:String = this._playerProxy.playerData.playlistCurrentQuality;
         if(_loc1_ == "flv" && this._showTimeoutCount < 3)
         {
            this._playerProxy.dispatchEvent(new CoreEvent(CoreEvent.BUFFER_TIMEOUT));
            this._showTimeoutCount++;
         }
      }
      
      private function tryToShowInformation() : void {
         var _loc1_:String = this._playerProxy.playerData.playlistCurrentQuality;
         if(!this._isBufferInfoShowed)
         {
            this._isBufferInfoShowed = true;
            if(_loc1_ == "mp4" || _loc1_ == "hd2")
            {
               this._playerProxy.dispatchEvent(new CoreEvent(CoreEvent.BUFFER_TEMP_SWITCH_TO_LOW));
            }
            else if(_loc1_ == "flv")
            {
               if(PlayerConfig.isRTMP)
               {
                  return;
               }
               if(this._playerProxy.playerData.isIKuInstall)
               {
                  this._playerProxy.dispatchEvent(new CoreEvent(CoreEvent.BUFFER_PAUSE_IKU));
               }
               else
               {
                  this._playerProxy.dispatchEvent(new CoreEvent(CoreEvent.BUFFER_INSTALL_IKU));
               }
            }
            
         }
      }
      
      private function playVideoByID(param1:String, param2:String = null) : void {
         this._ltgetplaylist = 0;
         this._stgetplaylist = getTimer();
         PlayerConfig.loadtimeData.ltgetplaylist_start = new Date().getTime();
         this._rootData.videoId = param1;
         this._playerProxy.dispatchEvent(new CoreFacadeEvent(CoreFacadeEvent.LOAD_PLAY_LIST_DATA,{"othervid":param2}));
      }
   }
}
